package com.yuexun.dhdoctor.module.my.ui;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.base.BaseEntity;
import com.yuexun.dhdoctor.base.BaseKJActivity;
import com.yuexun.dhdoctor.config.AppConfig;
import com.yuexun.dhdoctor.module.my.model.impl.FeedbackModel;
import com.yuexun.dhdoctor.module.my.presenter.impl.FeedbackPresenter;
import com.yuexun.dhdoctor.module.my.ui.view.IFeedbackView;

import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by work-jx on 2016/8/4.
 */
public class Act_Feedback extends BaseKJActivity implements IFeedbackView {

    @Bind(R.id.feedback_edt)
    EditText feedbackEdt;
    @Bind(R.id.feedback_count_tv)
    TextView feedbackCountTv;

    FeedbackPresenter presenter;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_feedback);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        presenter = new FeedbackPresenter(new FeedbackModel(),this);
        feedbackEdt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                feedbackCountTv.setText(s.length()+"/200");
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }


    @OnClick({R.id.back, R.id.feedback_commit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.feedback_commit:
                if(!feedbackEdt.getText().toString().trim().isEmpty()){
                    Map<String, String> params = new HashMap<>();
                    params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
                    params.put("content", feedbackEdt.getText().toString());
                    presenter.createFeedback(params);
                }else{
                    ViewInject.toast("输入内容为空！不允许提交");
                }

                break;
        }
    }

    @Override
    public void createFeedback(BaseEntity baseBean) {
        if(baseBean.getStatus().equals("200"))
        {
            ViewInject.toast("提交成功");
            feedbackEdt.setText("");
            finish();
        }
        else {
            ViewInject.toast("提交失败，请重新提交");
        }
    }
}
